import java.sql.*;

public class jdbctest1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        //获取驱动Driver
        Class.forName("com.mysql.cj.jdbc.Driver");

        String url = "jdbc:mysql://localhost:3306/test10.31?useUnicode=true&characterEncoding=utf8&useSSL=false";
        String name = "root";
        String password = "try.10816";  //输入自己数据库的密码

        //输入用户名和密码
        Connection connection = DriverManager.getConnection(url,name,password);

        //执行sql的操作对象 statement
        Statement statement = connection.createStatement();

        //执行我们对应的sql语句
        String sql = "SELECT * FROM student";

        //获取执行出来的结果

        //对结果处理
        ResultSet resultSet = statement.executeQuery(sql);

        while (resultSet.next()){
            System.out.println("名字是" + resultSet.getObject("name"));
            System.out.println("年龄是" + resultSet.getObject("age"));
            System.out.println("家在" + resultSet.getObject("home"));
            System.out.println("班级是" + resultSet.getObject("class"));
        }
        resultSet.close();
        statement.close();
        connection.close();


    }
}